package com.baihan.angus.app.game.busshow.pop_dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;

import com.baihan.angus.app.game.basic.utils.ComUtil;
import com.baihan.angus.app.game.busshow.R;

public class SelectPicDialog extends Dialog {

    private Callback mCallback;
    private Context mContext;
    private WindowManager.LayoutParams mLayoutParams;
    private ImageView ivClose;
    private LinearLayout llTakePhoto, llAlbum;

    public SelectPicDialog(@NonNull Context context, Callback mCallback) {
        super(context, R.style.FullDialog);
        this.mContext = context;
        this.mCallback = mCallback;
        initContentView();
        init(context);
    }

    private void init(Context context) {
        this.mContext = context;
        Window dialogWindow = this.getWindow();
        mLayoutParams = dialogWindow.getAttributes();
//        mLayoutParams.width = AppUtil.getScreenWidth(context);
        mLayoutParams.width = ComUtil.Dp2Px(context, 255);
        mLayoutParams.height = ComUtil.Dp2Px(context, 187);
        dialogWindow.setAttributes(mLayoutParams);
//        dialogWindow.getDecorView().setPadding(80, 0, 80, 0);
        dialogWindow.getDecorView().setBackgroundResource(android.R.color.transparent);
        dialogWindow.setGravity(Gravity.CENTER);
    }

    private void initContentView() {
        View dialogView = LayoutInflater.from(this.getContext()).inflate(R.layout.dialog_select_pic, (ViewGroup) null);
        setContentView(dialogView);
        llTakePhoto = dialogView.findViewById(R.id.llTakePhoto);
        llAlbum = dialogView.findViewById(R.id.llAlbum);
        ivClose = dialogView.findViewById(R.id.ivClose);

        llTakePhoto.setOnClickListener(view -> {
            if (null != mCallback) {
                mCallback.onTakePhoto();
            }
        });

        llAlbum.setOnClickListener(view -> {
            if (null != mCallback) {
                mCallback.onAlbum();
            }
        });

        ivClose.setOnClickListener(view -> {
            cancel();
        });

    }

    public interface Callback {
        void onTakePhoto();

        void onAlbum();
    }
}
